/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2010
 */

package com.hibernate.model;


import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import cn.org.rapid_framework.util.DateConvertUtils;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "AD_OWNER")
public class AdOwner extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "AdOwner";
	public static final String ALIAS_ID = "id";
	public static final String ALIAS_USER_ID = "userId";
	public static final String ALIAS_COMPANY_NAME = "companyName";
	public static final String ALIAS_WEBSITE = "website";
	public static final String ALIAS_LINKMAN = "linkman";
	public static final String ALIAS_EMAIL = "email";
	public static final String ALIAS_MOBILE = "mobile";
	public static final String ALIAS_PHONE = "phone";
	public static final String ALIAS_INDUSTRY_ID = "industryId";
	public static final String ALIAS_ADDRESS = "address";
	public static final String ALIAS_REMARK = "remark";
	public static final String ALIAS_CREATION_TIME = "creationTime";
	public static final String ALIAS_STATUS = "status";
	
	//date formats
	public static final String FORMAT_CREATION_TIME = DATE_TIME_FORMAT;
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	
	private Long id;

	private Long userId;
	@NotBlank @Length(max=200)
	private java.lang.String companyName;
	@NotBlank @Length(max=100)
	private java.lang.String website;
	@NotBlank @Length(max=50)
	private java.lang.String linkman;
	@NotBlank @Length(max=50)
	private java.lang.String email;
	@Length(max=11)
	private java.lang.String mobile;
	@Length(max=20)
	private java.lang.String phone;

	private Long industryId;
	@Length(max=200)
	private java.lang.String address;
	@Length(max=1000)
	private java.lang.String remark;
	@NotNull 
	private java.util.Date creationTime;
	@NotBlank @Length(max=1)
	private java.lang.String status;
	
	private java.lang.String password;
	@Length(max=255)
	private String otherCode;


	
	
	@Length(max=50)
	private java.lang.String websiteDomain;
	@Length(max=50)
	private java.lang.String scale;
	@Length(max=10)
	private java.lang.String popularity;
	@Length(max=50)
	private java.lang.String newIndustry;
	

	//columns END
	public AdOwner(){
	}

	public AdOwner(
		Long id
	){
		this.id = id;
	}

	



	public void setId(Long value) {
		this.id = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getId() {
		return this.id;
	}
	
	@Column(name = "USER_ID", unique = false, insertable = true, updatable = true, length = 20)
	public Long getUserId() {
		return this.userId;
	}
	
	public void setUserId(Long value) {
		this.userId = value;
	}
	
	@Column(name = "PASSWORD")
	public java.lang.String getPassword() {
		return password;
	}

	public void setPassword(java.lang.String password) {
		this.password = password;
	}

	@Column(name = "COMPANY_NAME", unique = false, nullable = false, insertable = true, updatable = true, length = 200)
	public java.lang.String getCompanyName() {
		return this.companyName;
	}
	
	public void setCompanyName(java.lang.String value) {
		this.companyName = value;
	}
	
	@Column(name = "WEBSITE", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	public java.lang.String getWebsite() {
		return this.website;
	}
	
	public void setWebsite(java.lang.String value) {
		this.website = value;
	}
	
	@Column(name = "LINKMAN", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
	public java.lang.String getLinkman() {
		return this.linkman;
	}
	
	public void setLinkman(java.lang.String value) {
		this.linkman = value;
	}
	
	@Column(name = "EMAIL", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
	public java.lang.String getEmail() {
		return this.email;
	}
	
	public void setEmail(java.lang.String value) {
		this.email = value;
	}
	
	@Column(name = "MOBILE", unique = false, nullable = true, insertable = true, updatable = true, length = 11)
	public java.lang.String getMobile() {
		return this.mobile;
	}
	
	public void setMobile(java.lang.String value) {
		this.mobile = value;
	}
	
	@Column(name = "PHONE", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public java.lang.String getPhone() {
		return this.phone;
	}
	
	public void setPhone(java.lang.String value) {
		this.phone = value;
	}
	
	@Column(name = "INDUSTRY_ID", unique = false, insertable = true, updatable = true, length = 20)
	public Long getIndustryId() {
		return this.industryId;
	}
	
	public void setIndustryId(Long value) {
		this.industryId = value;
	}
	
	@Column(name = "ADDRESS", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public java.lang.String getAddress() {
		return this.address;
	}
	
	public void setAddress(java.lang.String value) {
		this.address = value;
	}
	
	@Column(name = "REMARK", unique = false, nullable = true, insertable = true, updatable = true, length = 1000)
	public java.lang.String getRemark() {
		return this.remark;
	}
	
	public void setRemark(java.lang.String value) {
		this.remark = value;
	}
	
	@Transient
	public String getCreationTimeString() {
		return DateConvertUtils.format(getCreationTime(), FORMAT_CREATION_TIME);
	}
	public void setCreationTimeString(String value) {
		setCreationTime(DateConvertUtils.parse(value, FORMAT_CREATION_TIME,java.util.Date.class));
	}
	
	@Column(name = "CREATION_TIME", unique = false, insertable = true, updatable = true, length = 7)
	public java.util.Date getCreationTime() {
		return this.creationTime;
	}
	
	public void setCreationTime(java.util.Date value) {
		this.creationTime = value;
	}
	
	@Column(name = "STATUS", unique = false, insertable = true, updatable = true, length = 1)
	public java.lang.String getStatus() {
		return this.status;
	}
	
	public void setStatus(java.lang.String value) {
		this.status = value;
	}
	
	
	@SuppressWarnings("rawtypes")
	private Set adOrders = new HashSet(0);
	public void setAdOrders(Set<AdOrder> adOrder){
		this.adOrders = adOrder;
	}
	
	@SuppressWarnings("unchecked")
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "adOwner")
	@OrderBy("name")
	public Set<AdOrder> getAdOrders() {
		return adOrders;
	}
	
	private Industry industry;
	public void setIndustry(Industry industry){
		if(industry != null)
			industry.getName();
		this.industry = industry;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "INDUSTRY_ID",nullable = false, insertable = false, updatable = false) 
	})
	public Industry getIndustry() {
		return industry;
	}
	
	private AcctUser acctUser;
	public void setAcctUser(AcctUser acctUser){
		this.acctUser = acctUser;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "USER_ID",nullable = false, insertable = false, updatable = false) 
	})
	public AcctUser getAcctUser() {
		return acctUser;
	}
	
	@Column(name = "OTHER_CODE", unique = false, nullable = true, insertable = true, updatable = true, length = 255)
	public String getOtherCode() {
		return otherCode;
	}

	public void setOtherCode(String otherCode) {
		this.otherCode = otherCode;
	}
	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("UserId",getUserId())
			.append("CompanyName",getCompanyName())
			.append("Website",getWebsite())
			.append("Linkman",getLinkman())
			.append("Email",getEmail())
			.append("Mobile",getMobile())
			.append("Phone",getPhone())
			.append("IndustryId",getIndustryId())
			.append("Address",getAddress())
			.append("Remark",getRemark())
			.append("CreationTime",getCreationTime())
			.append("Status",getStatus())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof AdOwner == false) return false;
		if(this == obj) return true;
		AdOwner other = (AdOwner)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}
	
	

	@Column(name = "SCALE", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	public java.lang.String getScale() {
		return this.scale;
	}
	
	public void setScale(java.lang.String value) {
		this.scale = value;
	}
	
	@Column(name = "POPULARITY", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
	public java.lang.String getPopularity() {
		return this.popularity;
	}
	
	public void setPopularity(java.lang.String value) {
		this.popularity = value;
	}
	
	@Column(name = "WEBSITE_DOMAIN", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	public java.lang.String getWebsiteDomain() {
		return this.websiteDomain;
	}
	
	public void setWebsiteDomain(java.lang.String value) {
		this.websiteDomain = value;
	}
	
	@Column(name = "NEW_INDUSTRY", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	public java.lang.String getNewIndustry() {
		return this.newIndustry;
	}
	
	public void setNewIndustry(java.lang.String value) {
		this.newIndustry = value;
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "广告主";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}

	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return getCompanyName();
	}

}

